package com.zline.foodraise.view;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.zline.foodraise.R;
import com.zline.foodraise.entity.CustomerUserBean;
import com.zline.foodraise.listener.RecyclerItemClicked;
import com.zline.foodraise.util.ImageUtil;
import com.zline.foodraise.util.LUtil;

import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;
import org.androidannotations.annotations.res.StringRes;

/**
 * Created by heshantao on 15/6/29.
 * <p/>
 * 用户关注列表
 */
@EViewGroup(R.layout.attention_list_item)
public class AttentionListItem extends RelativeLayout {
    private static final String LOG_TAG = AttentionListItem.class.getSimpleName();
    @ViewById(R.id.attention_list_item_person_icon_circleIv)
    CircleImageView person_civ;
    @ViewById(R.id.attention_list_item_vip)
    ImageView vip_iv;
    @ViewById(R.id.attention_list_item_person_nickname_tv)
    TextView person_nickName;
    @ViewById(R.id.attention_list_item_person_signature_tv)
    TextView person_signature;
    @ViewById(R.id.attention_list_item_attention_status_tv)
    TextView isAttention_tv;
    @StringRes(R.string.add_attention)
    String add_attention;
    @StringRes(R.string.unAttention)
    String cancel_attention;
    RecyclerItemClicked itemClicked;
    int position;
    @Bean
    ImageUtil imageUtil;
    String imageUri;
    int authenticateType;

    public AttentionListItem(Context context) {
        super(context);
    }

    public void bind(CustomerUserBean user,DisplayImageOptions options) {
        person_nickName.setText(user.getNickName());
        person_signature.setText(user.getSignature());
        int attention = user.getIsAttention();
        ImageLoader imageLoader = ImageLoader.getInstance();
        imageUri = user.getAvatarPicUrl();
        authenticateType = user.getIdentificateType();
        if (authenticateType == 1) {
            vip_iv.setVisibility(View.VISIBLE);
        } else {
            vip_iv.setVisibility(View.GONE);
        }
        imageLoader.displayImage(imageUri, person_civ, options);
        changeAttentaionStatus(attention);
    }


    public void setListener(RecyclerItemClicked listener, int position) {
        this.itemClicked = listener;
        this.position = position;

    }

    @Click({R.id.attention_list_item_attention_status_tv, R.id.attention_list_item_rl})
    void onClick(View view) {
        switch (view.getId()) {
            case R.id.attention_list_item_attention_status_tv:
                itemClicked.onRecyclerItemClicked(position);
                break;
            case R.id.attention_list_item_rl:
                itemClicked.onRecyclerItemClicked(0, position);
                break;
            default:
                break;
        }

    }

    //关注按钮的状态改变
    void changeAttentaionStatus(int isAttention) {
        LUtil.i(LOG_TAG, "______________isAttention________" + isAttention);
        if (isAttention == 1) {
            isAttention_tv.setBackgroundResource(R.drawable.attention_list_item_tv_attention);
            isAttention_tv.setText(cancel_attention);
        } else {
            isAttention_tv.setBackgroundResource(R.drawable.attention_list_item_tv_unattention);
            isAttention_tv.setText(add_attention);
        }
    }
}
